/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package counter.stosc.com;

import javax.microedition.lcdui.*;

/**
 *
 * @author Stosc
 */
class EditCounterUI extends Form implements CommandListener {

    private Controller controller;
    private Counter counter;

    private Command ok = new Command("确定", Command.OK, 0);
    private Command cancel = new Command("取消", Command.CANCEL, 0);

    private TextField counterName = new TextField("修学的内容", "", 20, TextField.ANY);
    private TextField scheduleCount = new TextField("预设完成的次数：", "", 20, TextField.NUMERIC);



    public  EditCounterUI (Controller controller) {
        super("编辑修学计数器");
        this.controller = controller;
        append(counterName);
        append(scheduleCount);

        addCommand(ok);
        addCommand(cancel);
        setCommandListener(this);
    }

    public void load(Counter counter) {
        this.counter = counter;
        counterName.setString(this.counter.getCounterName());
        scheduleCount.setString(String.valueOf(this.counter.getScheduleCount()));
    }

    public void commandAction(Command c, Displayable d) {
        if(c==cancel)
            controller.handleCommand(Controller.SHOW_LIST_COUNTER, null);
        if(c==ok ) {
            counter.setCounterName(counterName.getString());
            counter.setScheduleCount(Integer.parseInt(scheduleCount.getString()));
            controller.handleCommand(Controller.DO_UPDATE_COUNTER, counter);
        }
    }

}
